package top.abrsm.mapper;

import org.apache.ibatis.annotations.Select;
import top.abrsm.entity.ProductEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * <p>
 * 商品表 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2023-11-18
 */
@Mapper
public interface ProductMapper extends BaseMapper<ProductEntity> {

    @Select ( value = "<script>select * from product_info pi <where><if test='id!=null'>pi.id=#{id}</if><if test='categoryId!=null'> and pi.categoryId=#{categoryId}</if><if test='productName!=null'> and pi.productName like CONCAT('%', #{productName, jdbcType=VARCHAR}, '%')</if><if test='isUsed != null'> and pi.isUsed=#{isUsed}</if><if test='actualPrice!=null'> order by CONVERT(pi.actualPrice,DECIMAL) desc</if></where>limit #{offset},#{limit}</script>" )
    List<ProductEntity> queryList ( String id, String categoryId, String productName, String actualPrice, Integer isUsed, Integer offset, Integer limit );

    @Select ( value = "<script>select count(1) from product_info pi <where><if test='id!=null'>pi.id=#{id}</if><if test='categoryId!=null'> and pi.categoryId=#{categoryId}</if><if test='productName!=null'> and pi.productName like CONCAT('%', #{productName, jdbcType=VARCHAR}, '%')</if><if test='isUsed != null'> and pi.isUsed=#{isUsed}</if></where></script>" )
    Integer queryCount ( String id, String categoryId, String productName, Integer isUsed );


}
